What is @types/urijs?
@types/urijs provides TypeScript type definitions for the URI.js library, which is used for URL manipulation and parsing.
What are @types/urijs's main functionalities?
Parsing URLs
This feature allows you to parse a URL into its components such as protocol, hostname, port, path, query, and fragment.
const URI = require('urijs');
const uri = new URI('https://example.com:8080/path?query=1#fragment');
console.log(uri.protocol()); // 'https'
console.log(uri.hostname()); // 'example.com'
console.log(uri.port()); // '8080'
console.log(uri.path()); // '/path'
console.log(uri.query()); // 'query=1'
console.log(uri.fragment()); // 'fragment'
Building URLs
This feature allows you to build a URL by setting its components such as protocol, hostname, port, path, query, and fragment.
const URI = require('urijs');
const uri = new URI();
uri.protocol('https')
.hostname('example.com')
.port(8080)
.path('/path')
.query('query=1')
.fragment('fragment');
console.log(uri.toString()); // 'https://example.com:8080/path?query=1#fragment'
Manipulating Query Parameters
This feature allows you to manipulate query parameters in a URL by adding or removing them.
const URI = require('urijs');
const uri = new URI('https://example.com/path?query=1');
uri.addQuery('newParam', 'newValue');
console.log(uri.toString()); // 'https://example.com/path?query=1&newParam=newValue'
uri.removeQuery('query');
console.log(uri.toString()); // 'https://example.com/path?newParam=newValue'
Other packages similar to @types/urijs
query-string
The query-string package is used for parsing and stringifying URL query strings. It is simpler and more focused on query string manipulation compared to URI.js, which offers a broader range of URL manipulation features.
url-parse
The url-parse package provides similar functionality to URI.js for parsing and manipulating URLs. It is lightweight and focuses on URL parsing and construction, but may not offer as many features as URI.js.
whatwg-url
The whatwg-url package is a full implementation of the WHATWG URL Standard. It provides comprehensive URL parsing and manipulation capabilities, similar to URI.js, but follows the WHATWG specifications closely.
Installation
npm install --save @types/urijs
Summary
This package contains type definitions for urijs (http://medialize.github.io/URI.js).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/urijs.
Additional Details
- Last updated: Wed, 22 Nov 2023 00:24:48 GMT
- Dependencies: none
Credits
These definitions were written by RodneyJT, Brian Surowiec, Pete Johanson, Zhibin Liu, TeamworkGuy2, Akuukis, Marcell Toth, Vincenzo Chianese, Andree Hagelstein, and Alexander Pepper.